package com.heyou.config;


import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeEmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeServerlessIndexConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EmbeddingStoreConfig {

    @Autowired
    private EmbeddingModel embeddingModel;

    @Bean
    public EmbeddingStore<TextSegment> embeddingStore() {
        // 创建向量存储
        EmbeddingStore<TextSegment> embeddingStore = PineconeEmbeddingStore.builder()
                .apiKey(System.getenv("PINECONE_API_KEY"))
                // 若索引不存在，则会新建
                .index("heyou-agent-index")
                // 若名称空间不存在，则会新建
                .nameSpace("heyou-agent-namespace")
                .createIndex(PineconeServerlessIndexConfig.builder()
                        // 指定索引部署在AWS服务器
                        .cloud("AWS")
                        // 指定索引所在的AWS区域在us-east-1
                        .region("us-east-1")
                        // 指定索引的向量维度，该维度与embeddedModel生成的向量维度相同。
                        .dimension(embeddingModel.dimension()).build())
                .build();
        return embeddingStore;
    }
}
